Type.registerNamespace("Telerik.Web.UI.Scheduler.Views.Timeline.GroupedByResource");
(function(){var b=$telerik.$,d,c=Telerik.Web.UI.Scheduler,a=c.Views.Timeline;
a.GroupedByResource.Model=function(e,g,f){a.GroupedByResource.Model.initializeBase(this,[e]);
this._groupingResource=g;
this._isVertical=f;
this._timelineModels=[];
this._resources=null;
if(Telerik.Web.UI.Scheduler.Rendering.HorizontalBlockCollection){this._allDayBlocks=new Telerik.Web.UI.Scheduler.Rendering.HorizontalBlockCollection();
}};
a.GroupedByResource.Model.prototype={initialize:function(){this._resources=this._owner.get_resources().getResourcesByType(this._groupingResource);
for(var e=0;
e<this._resources.get_count();
e++){this._timelineModels[e]=new a.Model(this._owner);
}},addToBlocks:function(f){var e=this._getAppointmentModelIndex(f.appointment);
f.appointment.__modelIndex=e;
this._timelineModels[e].addToBlocks(f);
},removeFromBlock:function(f){var e=f.appointment.__modelIndex;
this._timelineModels[e].removeFromBlock(f);
},getTimeSlotFromDomElement:function(g){var f=this._getRawIndexFromDomElement(g);
var e=this._getTimeFromDomElement(g);
var i=this._resources.getResource(f.modelIndex);
var h=this._timelineModels[0]._slotDurationInMinutes;
return new a.GroupedByResource.TimeSlot(f,e,h,i,g);
},getDurationOfMovedAppointment:function(e){return e.get_duration();
},_getMaxAppointmentGrowth:function(f){if(this._isVertical){return this._getNumberOfSlots();
}else{var e=this.getTimeSlotFromDomElement(f);
return(this._getNumberOfSlots()-e.get_rawIndex().intervalIndex-1);
}},_getTimeFromDomElement:function(e){var f=this._getRawIndexFromDomElement(e);
return this._timelineModels[0]._getTimeFromIndex(f);
},_getRawIndexFromDomElement:function(f){while(f&&(f.tagName.toUpperCase()!="TD")){f=f.parentNode;
}if(!f){return null;
}var e=f.parentNode;
if(!this._isVertical){var h=e.cells.length/this._resources.get_count();
var i=Math.floor(f.cellIndex/h);
var g=f.cellIndex-(i*h);
return{intervalIndex:g,modelIndex:i};
}else{return{intervalIndex:f.cellIndex,modelIndex:e.rowIndex};
}},_getRawIndexFromStartTime:function(e){return this._timelineModels[0]._getRawIndexFromStartTime(e);
},_getAppointmentModelIndex:function(e){var f=-1;
var g=this;
e.get_resources().forEach(function(h){var i=g._resources.getResourceByTypeAndKey(h.get_type(),h.get_key());
if(i){f=Array.indexOf(g._resources._array,i);
}});
return f;
},_getAllDayTimeSlotForAppointmentPart:function(e){return this._getAllDayTimeSlot(e.start,e.modelIndex);
},_getAllDayTimeSlot:function(g,j){var e=this._getRawIndexFromStartTime(g);
e.modelIndex=j;
var f=this._getDomElementFromRawIndex(e);
var i=this._resources.getResource(e.modelIndex);
var h=this._timelineModels[0]._slotDurationInMinutes;
return new a.GroupedByResource.TimeSlot(e,g,h,i,f);
},getTimeSlotForAppointment:function(e){var f=this._getAppointmentModelIndex(e);
if(f==-1){return null;
}return this._getAllDayTimeSlot(e.get_start(),f);
},_getDomElementFromRawIndex:function(e){if(e.modelIndex===d){return this._timelineModels[0]._getDomElementFromRawIndex(e.intervalIndex);
}var f=this._owner.get_element();
var g=e.modelIndex;
var h=e.intervalIndex;
if(this._isVertical){return b("div.rsTimelineView table.rsAllDayTable",f)[0].tBodies[0].rows[g].cells[h];
}h+=this._getNumberOfSlots()*e.modelIndex;
return b("div.rsTimelineView table.rsAllDayTable",f)[0].tBodies[0].rows[0].cells[h];
},isVisible:function(e){var f=a.GroupedByResource.Model.callBaseMethod(this,"isVisible",[e]);
var g=this._getAppointmentModelIndex(e)!=-1;
return f&&g;
},_getRenderer:function(){if(!this._renderer){this._renderer=new c.Rendering.ResourceGroupedTimelineViewRenderer(this);
}return this._renderer;
}};
a.GroupedByResource.Model.registerClass("Telerik.Web.UI.Scheduler.Views.Timeline.GroupedByResource.Model",a.ModelBase);
a.GroupedByResource.TimeSlot=function(f,e,h,i,g){this._resource=i;
a.GroupedByResource.TimeSlot.initializeBase(this,[f,e,h,g]);
};
a.GroupedByResource.TimeSlot.prototype={get_index:function(){var e=this.get_rawIndex();
var f=a.GroupedByResource.TimeSlot.callBaseMethod(this,"get_index");
return String.format("{0}:{1}",e.modelIndex,f);
},get_resource:function(){return this._resource;
}};
a.GroupedByResource.TimeSlot.registerClass("Telerik.Web.UI.Scheduler.Views.Timeline.GroupedByResource.TimeSlot",a.TimeSlot);
})();
